import { defineStore } from "pinia";
import { MessageState } from "/@ts/types/system";
import { myMsg, myTodo } from "/@ts/layouts/components/api";

import router from "/@ts/router";
export const useMessageStore = defineStore("Message", {
  state: (): MessageState => {
    return {
      myMsg: [],
      myTodo: [],
    };
  },
  getters: {
    getmyMsg(){
      return this.myMsg;
    },
    getmyTodo() {
      return this.myTodo;
    },
  },
  actions: {
    setMyTodo(data: any) {
      this.myTodo = data;
      
    },
        myMsgUpdate(){
         return new Promise((resolve, reject) => {
          
          myMsg({
             status:1
          })
            .then((res: ResponseConfig) => {
              this.setMyMsg(res.rows);
              resolve(res.rows);
            })
            .catch((error: Error) => {
              reject(error);
            });
        });
    },
    myTodoUpdate(){
         return new Promise((resolve, reject) => {
          
          myTodo({
           status:1
          })
            .then((res: ResponseConfig) => {
              this.setMyTodo(res.rows);
              resolve(res.rows);
            })
            .catch((error: Error) => {
              reject(error);
            });
        });
    },
   setMyMsg(data: any) {
      this.myMsg = data;
    },
  },
});

// 遍历后台传来的路由字符串，转换为组件对象
